package com.ruoyi.tb.lmt.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tb.lmt.domain.vo.TbPreflightVo;
import com.ruoyi.tb.lmt.domain.bo.TbPreflightBo;
import com.ruoyi.tb.lmt.service.ITbPreflightService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 过程验收主表
 *
 * @author ruoyi
 * @date 2024-01-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xha-lmt/preflight")
public class TbPreflightController extends BaseController {

    private final ITbPreflightService iTbPreflightService;

    /**
     * 查询过程验收主表列表
     */
    @SaCheckPermission("xha-lmt:preflight:list")
    @GetMapping("/list")
    public TableDataInfo<TbPreflightVo> list(TbPreflightBo bo, PageQuery pageQuery) {
        return iTbPreflightService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出过程验收主表列表
     */
    @SaCheckPermission("xha-lmt:preflight:export")
    @Log(title = "过程验收主表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TbPreflightBo bo, HttpServletResponse response) {
        List<TbPreflightVo> list = iTbPreflightService.queryList(bo);
        ExcelUtil.exportExcel(list, "过程验收主表", TbPreflightVo.class, response);
    }

    /**
     * 获取过程验收主表详细信息
     *
     * @param ID 主键
     */
    @SaCheckPermission("xha-lmt:preflight:query")
    @GetMapping("/{ID}")
    public R<TbPreflightVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long ID) {
        return R.ok(iTbPreflightService.queryById(ID));
    }

    /**
     * 新增过程验收主表
     */
    @SaCheckPermission("xha-lmt:preflight:add")
    @Log(title = "过程验收主表", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TbPreflightBo bo) {
        return toAjax(iTbPreflightService.insertByBo(bo));
    }

    /**
     * 修改过程验收主表
     */
    @SaCheckPermission("xha-lmt:preflight:edit")
    @Log(title = "过程验收主表", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TbPreflightBo bo) {
        return toAjax(iTbPreflightService.updateByBo(bo));
    }

    /**
     * 删除过程验收主表
     *
     * @param IDs 主键串
     */
    @SaCheckPermission("xha-lmt:preflight:remove")
    @Log(title = "过程验收主表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] IDs) {
        return toAjax(iTbPreflightService.deleteWithValidByIds(Arrays.asList(IDs), true));
    }
}
